package com.leapp.sk.viewdelegate.adapter.im

import android.content.Context
import android.widget.ImageView
import android.widget.TextView
import com.bumptech.glide.Glide
import com.bumptech.glide.RequestManager
import com.bumptech.glide.load.engine.DiskCacheStrategy
import com.bumptech.glide.request.RequestOptions
import com.example.mvp.delegate.BaseAdapterDelegate
import com.example.mvp.view.GlideCircleTransform
import com.leapp.sk.R
import com.leapp.sk.bean.EmojiconEntity

/**
 * 大表情表情适配器视图托管层
 * @author  chaohaipeng  on 2018/7/16.
 */
class EmojiconBigGridAdapterDelegate : BaseAdapterDelegate() {
    /**
     * 图片加载操作
     */
    var mRequestOptions: RequestOptions = RequestOptions()
    override fun getOptionsMenuId(): Int {
        return 0
    }

    override fun initWidget() {
    }

    override fun onDestroy() {
    }

    override fun initLayoutRes(): Int {
        return R.layout.sk_emogicon_big_expression
    }


    /**
     * 设置数据
     */
    fun setData(context: Context, emojicon: EmojiconEntity){
        val iv_sebe_expression =getView<ImageView>(R.id.iv_sebe_expression)
        val tv_sebe_name =getView<TextView>(R.id.tv_sebe_name)
        tv_sebe_name.text=emojicon.name
        if (emojicon.icon !== 0) {
            iv_sebe_expression.setImageResource(emojicon.icon)
        } else if (emojicon.iconPath != null) {
            val mRequestManager: RequestManager = Glide.with(context)
            mRequestOptions.diskCacheStrategy(DiskCacheStrategy.NONE)
            mRequestOptions.skipMemoryCache(true)
            mRequestOptions.error(R.mipmap.ease_default_expression)
            mRequestOptions.transforms(GlideCircleTransform(context))
            mRequestManager?.load(emojicon.iconPath)
                    ?.thumbnail(0.2f)
                    ?.apply(mRequestOptions)
                    ?.into(iv_sebe_expression)

        }

    }
}